package cn.tedu.sp03.controller;

import cn.tedu.entity.User;
import cn.tedu.service.UserService;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :Colin
 * @version 创建时间: 2021/9/9 14:52
 */
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId){
        User user = userService.getUser(userId);
        return JsonResult.ok().data(user);
    }

    // /8/score?score=1000,?前是路径,?后是参数
    @GetMapping("/{userId}/score")
    public JsonResult<?> addScore(@PathVariable Integer userId,
                                  @RequestParam("score")Integer score){//其中 @RequestParam("score")其实可以省略
        userService.addScore(userId, score);
        return JsonResult.ok().msg("增加积分成功");
    }

    @GetMapping("/favicon.ico")
    public void ico(){

    }
}
